<template>
  <div>
    <!--默认 :disabled-list="disabledList" -->
    <van-nav-bar
      title="地址列表"
      left-text="返回"
      right-text="Mine"
      left-arrow
      @click-left="onClickLeft"
      @click-right="onClickRight"
    />
    <van-address-list
      v-model="chosenAddressId"
      :list="list"
      disabled-text="以下地址超出配送范围"
      default-tag-text="默认"
      @add="onAdd"
      @edit="onEdit"
    />
  </div>
</template>

<script>
import { getaddresses } from "@/api/address";
import { Toast } from "vant";

export default {
  data() {
    return {
      chosenAddressId: "1",
      list: [],
    };
  },
  methods: {
    async addresslist() {
      let res = await getaddresses();
      console.log(res.addresses);
      let obj = {};
      let newList = [];
      res?.addresses.forEach((item) => {
        obj = {
          ...item,
          name: item.receiver,
          tel: item.mobile,
          address: item.regions,
          isDefault: item.isDefault,
          //   address:item.address+item.regions,
        };
        newList.push(obj);
      });
      console.log(newList);
      this.list = newList;
    },
    onAdd() {
      Toast("新增地址");
      this.$router.push("address");
    },
    onEdit(item, index) {
      Toast("编辑地址:" + index);
    },
    onClickLeft() {
      this.$router.go(-1);
      Toast("返回");
    },
    onClickRight() {
      this.$router.push("Mine");
      Toast("Mine");
    },
  },
  created() {
    this.addresslist();
  },
};
</script>

<style></style>
